package com.dyyx.mystarter.configuration;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;


@Configuration
public class MyStarter2AutoConfiguration{
	
	
	@Bean("myStarter2InitBean")
	public Map<String,String> init(Environment env) {
		Map<String,String> map = new HashMap<>();
		
		String[] defaultProfiles = env.getDefaultProfiles();
		String[] activeProfiles = env.getActiveProfiles();

		String appName = env.getProperty("app.name");
		map.put("appName",appName);
		map.put("defaultProfiles",arr2String(defaultProfiles));
		map.put("activeProfiles",arr2String(activeProfiles));

		System.out.println("\n\n\n");

	    System.out.println("MyStarter2AutoConfiguration myStarter2InitBean run,"+LocalDateTime.now()+","+map);
		System.out.println("\n\n\n");
		
		System.setProperty("myStarter2Enable", "true");
		
		
	    return map;
	}
	
	private static String arr2String(String[]arr) {
		if(arr==null) {
			return null;
		}
		return String.join(",", arr);
	}
	

	
}
